package com.nuedu.corejava.ch9.homework;

import java.util.Scanner;

public class Email {
	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);
		System.out.println("请输入一个邮箱地址：");
		String emailString = scanner.nextLine();
		if (emailString.indexOf("@")==-1 || emailString.indexOf(".")==-1) {
			System.out.println("邮箱地址中不包含@和“.”");}
			else if (emailString.indexOf("@") != emailString.lastIndexOf("@")
					||emailString.indexOf(".") != emailString.lastIndexOf(".")) {
				System.out.println("邮箱地址中包含多个@或“.”");
			}else if (emailString.indexOf("@") > emailString.indexOf(".")) {
				System.out.println("邮箱地址中@在“.”后面");
			}else if (!checkEmailContent(emailString)) {
				System.out.println("有其他字符");
			}else {
				System.out.println("有效");
			}
		}
	private static boolean checkEmailContent(String email) {
		for (int i = 0; i < email.length(); i++) {
			char c = email.charAt(i);
			boolean flag = c>='A'&&c<='Z' || c>='0'&&c<='9' ||c>='a'&&c<='z' || c=='@' ||  c=='.';
			if (flag) {
				continue;
			}else {
				return false;
			}
		
		}
		return true;
	}
		
				
	}


